<?php
class ArticleAction extends Action{
	function init(){
		$user=new MyModel();
		$this->my = $user;
		$us=$user->all;
		$this->assign('u', $us);
	}
	
	function cmdIndex(){
		
	}
	
	function cmdView(){
		/* $id=isset($_REQUEST['id'])?$_REQUEST['id']:null;
		$id=verify_id($id);
		$article=new ArticleModel();
		$this->assign('id',$id);
		$this->assign('view',$article->getView($id));
		$this->display("article_view.htm"); */
		$id=isset($_REQUEST['id'])?$_REQUEST['id']:null;
		$id=verify_id($id);
		$article=new ArticleModel();
		$re=$article->getRe($id);
		$readid=isset($_SESSION['article_read'])?$_SESSION['article_read']:0;
		if($readid!=$id)$article->setReadCount($id);
		$_SESSION['article_read']=$id;
		$this->assign('view',$article->getView($id));
		$this->assign('re', $re['data']);
		$this->assign('id', $id);
		$this->assign('recount', $re['count']);
		$this->display("article_view.htm");
	}
	
	function cmdReArticle(){
		$id=isset($_REQUEST['id'])?$_REQUEST['id']:null;
		$id=verify_id($id);
		$recont=isset($_POST['recontent'])?$_POST['recontent']:null;
		$nick=$this->my->all['user_nick'];
		$userid=$this->my->myid;
		$retime=$_SESSION['re_'.$id];
		if(time()-$retime<30)$this->Message("不要频繁回复!过".(30-(time()-$retime))."秒再来吧！","回复提示",str_replace("ReArticle", "View", getUrl(false)),3);
		if($recont==null || strlen($recont)<3){
			$this->Message("回复内容太短!","回复提示",str_replace("ReArticle", "View", getUrl(false)),3);
		}else{
			$article=new ArticleModel();
			$res=$article->ReArticle($id,$recont,$nick,$userid);
			$_SESSION['re_'.$id]=time();
			$this->Message($res,"回复提示",str_replace("ReArticle", "View", getUrl(false)),3);
		}
	
	}
	
	function cmdList(){
		$article=new ArticleModel();
		$page=isset($_GET['page'])?$_GET['page']:1;
		$pagesize=10;
		
		if($page)verify_id($page);
		$list=$article->getList(null,$page,$pagesize);
		$this->assign('list', $list['data']);
		$this->assign("title","文章列表");
		$this->assign('page', $page);
		$this->assign('pagesize', $pagesize);
		$this->assign('count', $list['count']);
		$this->assign('pagecount',$list['pagecount']);
		$this->display("article_list.htm");
	}
}